package com.aries.ui.view.radius.delegate;


import com.aries.ui.util.DrawableUtil;
import com.aries.ui.util.AttrUtils;
import ohos.agp.components.AbsButton;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Text;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.components.element.StateElement;
import ohos.agp.components.element.VectorElement;
import ohos.agp.utils.Color;
import ohos.agp.utils.LayoutAlignment;
import ohos.app.Context;

/**
 * @Author: AriesHoo on 2018/7/19 9:59
 * @E-Mail: AriesHoo@126.com
 * Function: TextView特有代理类
 * Description:
 * 1、2018-2-4 17:42:18 增加 CompoundButton 类(CheckBox和RadioButton)增加ButtonDrawable属性
 * 2、2018-2-5 11:02:51 增加TextView类设置drawable属性
 * 3、提前增加文本颜色值默认检查
 * 4、2018-5-31 16:59:59 新增部分遗漏java属性
 * 5、2018-5-31 17:00:47 修订设置Drawable后无法移除问题
 * 6、2018-6-3 22:01:53 优化部分TextColor 未设置时默认颜色逻辑
 * 7、2018-6-5 09:10:58 新增Left Top Right Bottom Drawable是否为系统属性配置
 * 8、2019-2-26 15:36:08 优化{@link #setTextDrawable(Element, Element, Element, Element, Element, int)} 逻辑
 */
public class RadiusTextDelegate<T extends RadiusTextDelegate> extends RadiusViewDelegate<T>  {

    private Text mTextView;
    protected int mTextColor;
    private int mTextPressedColor;
    private int mTextDisabledColor;
    private int mTextSelectedColor;
    protected int mTextCheckedColor;

    private boolean mLeftDrawableSystemEnable;
    private float mLeftDrawableColorRadius;
    private boolean mLeftDrawableColorCircleEnable;
    private int mLeftDrawableWidth;
    private int mLeftDrawableHeight;
    private Element mLeftDrawable;
    private Element mLeftPressedDrawable;
    private Element mLeftDisabledDrawable;
    private Element mLeftSelectedDrawable;
    private Element mLeftCheckedDrawable;

    private boolean mTopDrawableSystemEnable;
    private float mTopDrawableColorRadius;
    private boolean mTopDrawableColorCircleEnable;
    private int mTopDrawableWidth;
    private int mTopDrawableHeight;
    private Element mTopDrawable;
    private Element mTopPressedDrawable;
    private Element mTopDisabledDrawable;
    private Element mTopSelectedDrawable;
    private Element mTopCheckedDrawable;


    private boolean mRightDrawableSystemEnable;
    private float mRightDrawableColorRadius;
    private boolean mRightDrawableColorCircleEnable;
    private int mRightDrawableWidth;
    private int mRightDrawableHeight;
    private Element mRightDrawable;
    private Element mRightPressedDrawable;
    private Element mRightDisabledDrawable;
    private Element mRightSelectedDrawable;
    private Element mRightCheckedDrawable;

    private boolean mBottomDrawableSystemEnable;
    private float mBottomDrawableColorRadius;
    private boolean mBottomDrawableColorCircleEnable;
    private int mBottomDrawableWidth;
    private int mBottomDrawableHeight;
    private Element mBottomDrawable;
    private Element mBottomPressedDrawable;
    private Element mBottomDisabledDrawable;
    private Element mBottomSelectedDrawable;
    private Element mBottomCheckedDrawable;

    public RadiusTextDelegate(Text view, Context context, AttrSet attrs) {
        super(view, context, attrs);
    }

    @Override
    protected void initAttributes(Context context, AttrSet attrs) {

        mTextView = (Text) mView;
        mTextColor = AttrUtils.getColorFromAttr(attrs, "rv_textColor", Integer.MAX_VALUE);
        mTextColor = (mTextColor == Integer.MAX_VALUE ? mTextView.getTextColor().getValue() : mTextColor);
        mTextPressedColor = AttrUtils.getColorFromAttr(attrs, "rv_textPressedColor", Integer.MAX_VALUE);
        mTextDisabledColor = AttrUtils.getColorFromAttr(attrs, "rv_textDisabledColor", Integer.MAX_VALUE);
        mTextSelectedColor = AttrUtils.getColorFromAttr(attrs, "rv_textSelectedColor", Integer.MAX_VALUE);
       mTextCheckedColor = AttrUtils.getColorFromAttr(attrs, "rv_textCheckedColor", Integer.MAX_VALUE);

        mLeftDrawableSystemEnable = AttrUtils.getBooleanFromAttr(attrs, "rv_leftDrawableSystemEnable", false);
        mLeftDrawableColorRadius = AttrUtils.getDimensionFromAttr(attrs, "rv_leftDrawableColorRadius", 0);
        mLeftDrawableColorCircleEnable = AttrUtils.getBooleanFromAttr(attrs, "rv_leftDrawableColorCircleEnable", false);
        mLeftDrawableWidth = AttrUtils.getDimensionFromAttr(attrs, "rv_leftDrawableWidth", -1);
        mLeftDrawableHeight = AttrUtils.getDimensionFromAttr(attrs, "rv_leftDrawableHeight", -1);
        mLeftDrawable = getDrawable(context,attrs,"rv_leftDrawable");//AttrUtils.getElementFromAttr(attrs, "rv_leftDrawable", null);
        mLeftPressedDrawable = AttrUtils.getElementFromAttr(attrs, "rv_leftPressedDrawable", null);
        mLeftDisabledDrawable = AttrUtils.getElementFromAttr(attrs, "rv_leftDisabledDrawable", null);
        mLeftSelectedDrawable = AttrUtils.getElementFromAttr(attrs, "rv_leftSelectedDrawable", null);
        mLeftCheckedDrawable = AttrUtils.getElementFromAttr(attrs, "rv_leftCheckedDrawable", null);

        mTopDrawableSystemEnable = AttrUtils.getBooleanFromAttr(attrs, "rv_topDrawableSystemEnable", false);
        mTopDrawableColorRadius = AttrUtils.getDimensionFromAttr(attrs, "rv_topDrawableColorRadius", 0);
        mTopDrawableColorCircleEnable = AttrUtils.getBooleanFromAttr(attrs, "rv_topDrawableColorCircleEnable", false);
        mTopDrawableWidth = AttrUtils.getDimensionFromAttr(attrs, "rv_topDrawableWidth", -1);
        mTopDrawableHeight = AttrUtils.getDimensionFromAttr(attrs, "rv_topDrawableHeight", -1);
        mTopDrawable =  getDrawable(context,attrs, "rv_topDrawable");
        mTopPressedDrawable = AttrUtils.getElementFromAttr(attrs, "rv_topPressedDrawable", null);
        mTopDisabledDrawable = AttrUtils.getElementFromAttr(attrs, "rv_topDisabledDrawable", null);
        mTopSelectedDrawable = AttrUtils.getElementFromAttr(attrs, "rv_topSelectedDrawable", null);
        mTopCheckedDrawable = AttrUtils.getElementFromAttr(attrs, "rv_topCheckedDrawable", null);

        mRightDrawableSystemEnable = AttrUtils.getBooleanFromAttr(attrs, "rv_rightDrawableSystemEnable", false);
        mRightDrawableColorRadius = AttrUtils.getIntegerFromAttr(attrs, "rv_rightDrawableColorRadius", 0);
        mRightDrawableColorCircleEnable = AttrUtils.getBooleanFromAttr(attrs, "rv_rightDrawableColorCircleEnable", false);
        mRightDrawableWidth = AttrUtils.getDimensionFromAttr(attrs, "rv_rightDrawableWidth", -1);
        mRightDrawableHeight = AttrUtils.getDimensionFromAttr(attrs, "rv_rightDrawableHeight", -1);
        mRightDrawable = getDrawable(context, attrs, "rv_rightDrawable");
        mRightPressedDrawable = AttrUtils.getElementFromAttr(attrs, "rv_rightPressedDrawable", null);
        mRightDisabledDrawable = AttrUtils.getElementFromAttr(attrs, "rv_rightDisabledDrawable", null);
        mRightSelectedDrawable = AttrUtils.getElementFromAttr(attrs, "rv_rightSelectedDrawable", null);
        mRightCheckedDrawable = AttrUtils.getElementFromAttr(attrs, "rv_rightCheckedDrawable", null);

        mBottomDrawableSystemEnable = AttrUtils.getBooleanFromAttr(attrs, "rv_bottomDrawableSystemEnable", false);
        mBottomDrawableColorRadius = AttrUtils.getIntegerFromAttr(attrs, "rv_bottomDrawableColorRadius", 0);
        mBottomDrawableColorCircleEnable = AttrUtils.getBooleanFromAttr(attrs, "rv_bottomDrawableColorCircleEnable", false);
        mBottomDrawableWidth = AttrUtils.getDimensionFromAttr(attrs, "rv_bottomDrawableWidth", -1);
        mBottomDrawableHeight = AttrUtils.getDimensionFromAttr(attrs, "rv_bottomDrawableHeight", -1);
        mBottomDrawable =  getDrawable(context,attrs, "rv_bottomDrawable");
        mBottomPressedDrawable = AttrUtils.getElementFromAttr(attrs, "rv_bottomPressedDrawable", null);
        mBottomDisabledDrawable = AttrUtils.getElementFromAttr(attrs, "rv_bottomDisabledDrawable", null);
        mBottomSelectedDrawable = AttrUtils.getElementFromAttr(attrs, "rv_bottomSelectedDrawable", null);
        mBottomCheckedDrawable = AttrUtils.getElementFromAttr(attrs, "rv_bottomCheckedDrawable", null);
        super.initAttributes(context, attrs);
    }

    /**
     * 可能会存在两种情况，一种是color,一种是vector
     *
     * @param context
     * @param attrSet
     * @param attrName
     * @return Element
     */
    private Element getDrawable(Context context, AttrSet attrSet, String attrName) {
        Element element = AttrUtils.getElementFromAttr(attrSet, attrName, null);
        if (element != null) {
            return element;
        }
        element = AttrUtils.getVectorElementFormAttr(context, attrSet, attrName);
        return element;
    }

    @Override
    public void init() {
        super.init();
        setTextSelector();
        if (!mLeftDrawableSystemEnable) {
            setTextDrawable(mLeftDrawable, mLeftCheckedDrawable,
                    mLeftSelectedDrawable, mLeftPressedDrawable, mLeftDisabledDrawable, LayoutAlignment.LEFT);
        }
        if (!mTopDrawableSystemEnable) {
            setTextDrawable(mTopDrawable, mTopCheckedDrawable,
                    mTopSelectedDrawable, mTopPressedDrawable, mTopDisabledDrawable, LayoutAlignment.TOP);
        }
        if (!mRightDrawableSystemEnable) {
            setTextDrawable(mRightDrawable, mRightCheckedDrawable,
                    mRightSelectedDrawable, mRightPressedDrawable, mRightDisabledDrawable, LayoutAlignment.RIGHT);
        }
        if (!mBottomDrawableSystemEnable) {
            setTextDrawable(mBottomDrawable, mBottomCheckedDrawable,
                    mBottomSelectedDrawable, mBottomPressedDrawable, mBottomDisabledDrawable, LayoutAlignment.BOTTOM);
        }
    }

    /**
     * 设置文本常态颜色
     *
     * @param color
     * @return T
     */
    public T setTextColor(int color) {
        this.mTextColor = color;
        return back();
    }

    /**
     * 设置文本按下颜色
     *
     * @param color
     * @return T
     */
    public T setTextPressedColor(int color) {
        this.mTextPressedColor = color;
        return back();
    }

    /**
     * 设置文本不可点击状态颜色--setEnable(false)时的颜色{@link ohos.agp.components.Component#setEnabled(boolean)}
     *
     * @param color
     * @return T
     */
    public T setTextDisabledColor(int color) {
        this.mTextDisabledColor = color;
        return back();
    }

    /**
     * 设置文本selected颜色
     *
     * @param color
     * @return T
     */
    public T setTextSelectedColor(int color) {
        this.mTextSelectedColor = color;
        return back();
    }

    /**
     * 设置文本checked颜色
     *
     * @param color
     * @return T
     */
    public T setTextCheckedColor(int color) {
        this.mTextCheckedColor = color;
        return back();
    }

    /**
     * 是否使用系统自带属性
     *
     * @param leftDrawableSystemEnable
     * @return back()
     */
    public T setLeftDrawableSystemEnable(boolean leftDrawableSystemEnable) {
        mLeftDrawableSystemEnable = leftDrawableSystemEnable;
        return back();
    }

    public T setLeftDrawableColorRadius(float leftDrawableColorRadius) {
        mLeftDrawableColorRadius = leftDrawableColorRadius;
        return back();
    }

    public T setLeftDrawableColorCircleEnable(boolean leftDrawableColorCircleEnable) {
        mLeftDrawableColorCircleEnable = leftDrawableColorCircleEnable;
        return back();
    }

    public T setLeftDrawableWidth(int leftDrawableWidth) {
        mLeftDrawableWidth = leftDrawableWidth;
        return back();
    }

    public T setLeftDrawableHeight(int leftDrawableHeight) {
        mLeftDrawableHeight = leftDrawableHeight;
        return back();
    }

    /**
     * 设置左边drawable
     *
     * @param drawable
     * @return back()
     */
    public T setLeftDrawable(Element drawable) {
        mLeftDrawable = drawable;
        return back();
    }

    public T setLeftDrawable(int resId) {
        return setLeftDrawable(getDrawable(resId));
    }

    public T setLeftPressedDrawable(Element drawable) {
        mLeftPressedDrawable = drawable;
        return back();
    }

    public T setLeftPressedDrawable(int resId) {
        return setLeftPressedDrawable(getDrawable(resId));
    }

    public T setLeftDisabledDrawable(Element drawable) {
        mLeftDisabledDrawable = drawable;
        return back();
    }

    public T setLeftDisabledDrawable(int resId) {
        return setLeftDisabledDrawable(getDrawable(resId));
    }

    public T setLeftSelectedDrawable(Element drawable) {
        mLeftSelectedDrawable = drawable;
        return back();
    }

    public T setLeftSelectedDrawable(int resId) {
        return setLeftSelectedDrawable(getDrawable(resId));
    }

    public T setLeftCheckedDrawable(Element drawable) {
        mLeftCheckedDrawable = drawable;
        return back();
    }

    public T setLeftCheckedDrawable(int resId) {
        return setLeftCheckedDrawable(getDrawable(resId));
    }

    public T setTopDrawableSystemEnable(boolean topDrawableSystemEnable) {
        mTopDrawableSystemEnable = topDrawableSystemEnable;
        return back();
    }

    public T setTopDrawableColorRadius(float topDrawableColorRadius) {
        mTopDrawableColorRadius = topDrawableColorRadius;
        return back();
    }

    public T setTopDrawableColorCircleEnable(boolean topDrawableColorCircleEnable) {
        mTopDrawableColorCircleEnable = topDrawableColorCircleEnable;
        return back();
    }

    public T setTopDrawableWidth(int topDrawableWidth) {
        mTopDrawableWidth = topDrawableWidth;
        return back();
    }

    public T setTopDrawableHeight(int topDrawableHeight) {
        mTopDrawableHeight = topDrawableHeight;
        return back();
    }

    /**
     * 设置top drawable
     *
     * @param drawable
     * @return back()
     */
    public T setTopDrawable(Element drawable) {
        mTopDrawable = drawable;
        return back();
    }

    public T setTopDrawable(int resId) {
        return setTopDrawable(getDrawable(resId));
    }

    public T setTopPressedDrawable(Element drawable) {
        mTopPressedDrawable = drawable;
        return back();
    }

    public T setTopPressedDrawable(int resId) {
        return setTopPressedDrawable(getDrawable(resId));
    }

    public T setTopDisabledDrawable(Element drawable) {
        mTopDisabledDrawable = drawable;
        return back();
    }

    public T setTopDisabledDrawable(int resId) {
        return setTopDisabledDrawable(getDrawable(resId));
    }

    public T setTopSelectedDrawable(Element drawable) {
        mTopSelectedDrawable = drawable;
        return back();
    }

    public T setTopSelectedDrawable(int resId) {
        return setTopSelectedDrawable(getDrawable(resId));
    }

    public T setTopCheckedDrawable(Element drawable) {
        mTopCheckedDrawable = drawable;
        return back();
    }

    public T setTopCheckedDrawable(int resId) {
        return setTopCheckedDrawable(getDrawable(resId));
    }

    public T setRightDrawableSystemEnable(boolean rightDrawableSystemEnable) {
        mRightDrawableSystemEnable = rightDrawableSystemEnable;
        return back();
    }

    public T setRightDrawableColorRadius(float rightDrawableColorRadius) {
        mRightDrawableColorRadius = rightDrawableColorRadius;
        return back();
    }

    public T setRightDrawableColorCircleEnable(boolean rightDrawableColorCircleEnable) {
        mRightDrawableColorCircleEnable = rightDrawableColorCircleEnable;
        return back();
    }

    public T setRightDrawableWidth(int rightDrawableWidth) {
        mRightDrawableWidth = rightDrawableWidth;
        return back();
    }

    public T setRightDrawableHeight(int rightDrawableHeight) {
        mRightDrawableHeight = rightDrawableHeight;
        return back();
    }

    /**
     * 设置right drawable
     *
     * @param drawable
     * @return back()
     */
    public T setRightDrawable(Element drawable) {
        mRightDrawable = drawable;
        return back();
    }

    public T setRightDrawable(int resId) {
        return setRightDrawable(getDrawable(resId));
    }

    public T setRightPressedDrawable(Element drawable) {
        mRightPressedDrawable = drawable;
        return back();
    }

    public T setRightPressedDrawable(int resId) {
        return setRightPressedDrawable(getDrawable(resId));
    }

    public T setRightDisabledDrawable(Element drawable) {
        mRightDisabledDrawable = drawable;
        return back();
    }

    public T setRightDisabledDrawable(int resId) {
        return setRightDisabledDrawable(getDrawable(resId));
    }

    public T setRightSelectedDrawable(Element drawable) {
        mRightSelectedDrawable = drawable;
        return back();
    }

    public T setRightSelectedDrawable(int resId) {
        return setRightSelectedDrawable(getDrawable(resId));
    }

    public T setRightCheckedDrawable(Element drawable) {
        mRightCheckedDrawable = drawable;
        return back();
    }

    public T setRightCheckedDrawable(int resId) {
        return setRightCheckedDrawable(getDrawable(resId));
    }

    public T setBottomDrawableSystemEnable(boolean bottomDrawableSystemEnable) {
        mBottomDrawableSystemEnable = bottomDrawableSystemEnable;
        return back();
    }

    public T setBottomDrawableColorRadius(float bottomDrawableColorRadius) {
        mBottomDrawableColorRadius = bottomDrawableColorRadius;
        return back();
    }

    public T setBottomDrawableColorCircleEnable(boolean bottomDrawableColorCircleEnable) {
        mBottomDrawableColorCircleEnable = bottomDrawableColorCircleEnable;
        return back();
    }

    public T setBottomDrawableWidth(int bottomDrawableWidth) {
        mBottomDrawableWidth = bottomDrawableWidth;
        return back();
    }

    public T setBottomDrawableHeight(int bottomDrawableHeight) {
        mBottomDrawableHeight = bottomDrawableHeight;
        return back();
    }

    /**
     * 设置bottom drawable
     *
     * @param drawable
     * @return back()
     */
    public T setBottomDrawable(Element drawable) {
        mBottomDrawable = drawable;
        return back();
    }

    public T setBottomDrawable(int resId) {
        return setBottomDrawable(getDrawable(resId));
    }

    public T setBottomPressedDrawable(Element drawable) {
        mBottomPressedDrawable = drawable;
        return back();
    }

    public T setBottomPressedDrawable(int resId) {
        return setBottomPressedDrawable(getDrawable(resId));
    }

    public T setBottomDisabledDrawable(Element drawable) {
        mBottomDisabledDrawable = drawable;
        return back();
    }

    public T setBottomDisabledDrawable(int resId) {
        return setBottomDisabledDrawable(getDrawable(resId));
    }

    public T setBottomSelectedDrawable(Element drawable) {
        mBottomSelectedDrawable = drawable;
        return back();
    }

    public T setBottomSelectedDrawable(int resId) {
        return setBottomSelectedDrawable(getDrawable(resId));
    }

    public T setBottomCheckedDrawable(Element drawable) {
        mBottomCheckedDrawable = drawable;
        return back();
    }

    public T setBottomCheckedDrawable(int resId) {
        return setBottomCheckedDrawable(getDrawable(resId));
    }

    /**
     * 设置TextView的Left、Top、Right、Bottom Drawable属性
     *
     * @param normal
     * @param checked
     * @param selected
     * @param pressed
     * @param disabled
     * @param gravity
     */
    private void setTextDrawable(Element normal, Element checked, Element selected, Element pressed,
                                 Element disabled, int gravity) {
        int index = 0;
        int width = 0;
        int height = 0;
        float radius = 0.0f;
        switch (gravity) {
            case LayoutAlignment.LEFT:
                index = 0;
                width = mLeftDrawableWidth;
                height = mLeftDrawableHeight;
                radius = mLeftDrawableColorCircleEnable ? width + height / 2 : mLeftDrawableColorRadius;
                break;
            case LayoutAlignment.TOP:
                index = 1;
                width = mTopDrawableWidth;
                height = mTopDrawableHeight;
                radius = mTopDrawableColorCircleEnable ? width + height / 2 : mTopDrawableColorRadius;
                break;
            case LayoutAlignment.RIGHT:
                index = 2;
                width = mRightDrawableWidth;
                height = mRightDrawableHeight;
                radius = mRightDrawableColorCircleEnable ? width + height / 2 : mRightDrawableColorRadius;
                break;
            case LayoutAlignment.BOTTOM:
                index = 3;
                width = mBottomDrawableWidth;
                height = mBottomDrawableHeight;
                radius = mBottomDrawableColorCircleEnable ? width + height / 2 : mBottomDrawableColorRadius;
                break;
        }
        Element[] drawables = mTextView.getAroundElements();
        if (normal == null && pressed == null && disabled == null
                && selected == null && checked == null) {
            drawables[index] = null;
        } else {
            drawables[index] = null;
            StateElement stateDrawable = new StateElement();
            if (checked != null) {
                stateDrawable.addState(new int[]{mStateChecked}, getStateDrawable(checked, radius, width, height));
            }
            if (selected != null) {
                stateDrawable.addState(new int[]{mStateSelected}, getStateDrawable(selected, radius, width, height));
            }
            if (pressed != null) {
                stateDrawable.addState(new int[]{mStatePressed}, getStateDrawable(pressed, radius, width, height));
            }
            if (disabled != null) {
                stateDrawable.addState(new int[]{mStateDisabled}, getStateDrawable(disabled, radius, width, height));
            }
            if (normal != null) {
                stateDrawable.addState(new int[]{}, getStateDrawable(normal, radius, width, height));
            }
            drawables[index] = stateDrawable;
        }
        mTextView.setAroundElements(drawables[0], drawables[1], drawables[2], drawables[3]);
    }

    /**
     * 获取不同状态下的Drawable信息
     *
     * @param drawable
     * @param radius
     * @param width
     * @param height
     * @return Element
     */
    protected Element getStateDrawable(Element drawable, float radius, int width, int height) {
        if (drawable == null) return drawable;
        if (drawable instanceof ShapeElement) {
            ShapeElement shapeElement = (ShapeElement) drawable;
            shapeElement.setCornerRadius(radius);
        } else if (drawable instanceof VectorElement) {
            ((VectorElement) drawable).setAntiAlias(true);
        }
        DrawableUtil.setDrawableWidthHeight(drawable, width, height);
        return drawable;
    }

    /**
     * 设置文本颜色
     */
    private void setTextSelector() {

        if (mView instanceof AbsButton){
            AbsButton absButton = (AbsButton)mView;
            if (absButton.isChecked()&&mTextCheckedColor!=Integer.MAX_VALUE){
                absButton.setTextColorOn(new Color(mTextCheckedColor));
            }else {
                absButton.setTextColorOff(new Color(mTextColor));
            }
            return;
        }
        mTextView = (Text) mView;
        if (mTextView.isSelected()&&mTextSelectedColor!=Integer.MAX_VALUE) {
            mTextView.setTextColor(new Color(mTextSelectedColor));
            return;
        }
        if (mTextView.isPressed()&&mTextPressedColor!=Integer.MAX_VALUE) {
            mTextView.setTextColor(new Color(mTextPressedColor));
            return;
        }
        if (!mTextView.isEnabled()&&mTextDisabledColor!=Integer.MAX_VALUE) {
            mTextView.setTextColor(new Color(mTextDisabledColor));
            return;
        }

        mTextView.setTextColor(new Color(mTextColor));

    }

    private int getTextColor(int color) {
        if (color != Integer.MAX_VALUE) {
            return color;
        }
        if (mView.isSelected()) {
            color = mTextSelectedColor;
        } else if (mView instanceof AbsButton) {
            if (((AbsButton) mView).isChecked()) {
                color = mTextCheckedColor;
            }
        }
        int temp = mTextColor == Integer.MAX_VALUE ? Color.WHITE.getValue() : mTextColor;
        color = color != Integer.MAX_VALUE ? color : temp;
        return mView.isPressed() && !mRippleEnable ? calculateColor(color, mBackgroundPressedAlpha) : color;
    }

    /**
     * 根据drawable资源id返回drawable对象
     *
     * @param resId
     * @return Element
     */
    protected Element getDrawable(int resId) {
        return mResourceUtil.getImageDrawable(resId);
    }


}
